// 记分牌的类
class ScorePanel {
	score = 0; //分数
	level = 1; //登记
	maxLevel: number; //最大等级
	upScore: number; //多少分可以升级
	scoreEle: HTMLElement; //分数所在元素
	levelEle: HTMLElement; //等级所在元素

	constructor(maxLevel: number = 10, upScore: number = 10) {
		this.scoreEle = document.getElementById('score')!;
		this.levelEle = document.getElementById('level')!;
		this.maxLevel = maxLevel;
		this.upScore = upScore;
	}

	// 加分方法
	addScore() {
		// 分数自增
		this.scoreEle.innerHTML = ++this.score + '';
		// 判断是否可以升级
		if (this.score % this.upScore === 0) {
			this.levelUp();
		}
	}

	// 等级提升方法
	levelUp() {
		if (this.level < this.maxLevel) {
			this.levelEle.innerHTML = ++this.level + '';
		}
	}
}

export default ScorePanel;
